/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlador;

import java.util.*;
import modelo.ITarea;
import modelo.Tarea;
import modelo.ITareaModel;
import vista.ITareaView;
/**
 *
 * @author LEONIC
 */
public class TareaController implements ITareaController{

    private ITareaModel model;
    private List<ITareaView> views=new ArrayList<ITareaView>();

    public void setup(ITareaModel model, List<ITareaView> views) {
        setModel(model);
        addViews(views);
        model.setController(this);

    }

    public void start() {
        for(ITareaView view:views)
            view.display();
    }

    private void addViews(List<ITareaView> views){
        for(ITareaView view:views)
            addView(view);
    }
    public void addView(ITareaView view) {
        view.setModel(model);
        view.setController(this);
        views.add(view);
    }

    public void removeView(ITareaView view) {
        views.remove(view);
    }

    public ITareaModel getModel() {
        return model;
    }

    public void setModel(ITareaModel model) {
        this.model=model;
    }

    public void nuevoTareaGesture(String tar, String descripcion) {
        ITarea tarea=new Tarea(tar,descripcion);
        getModel().nuevoTarea(tarea);
    }

    public void actualizaTareaGesture(String tar, String descripcion) {
        ITarea tarea=new Tarea(tar,descripcion);
        getModel().actualizarTarea(tarea);
    }

    public void borraTareaGesture(String tar) {
        ITarea tarea=new Tarea(tar);
        getModel().eliminarTarea(tarea);
    }

    public void fireDataModelChanged() {
        for (ITareaView view : views) {
            view.dataModelChanged();
        }
    }

    public List<ITareaView> getViews(){
        return this.views;
    }
}
